package com.hospital.servlet;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hospital.util.DateUtil;
import com.hospital.util.DbUtil;
@WebServlet("/manage/MedicineInAndOut")
public class MedicineInAndOut extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {//药品的进货Servlet
		// TODO Auto-generated method stub
		/////进货/////
		String method = request.getParameter("method");
		if ("addjinhuo".equals(method)) {
			//String id=request.getParameter("id").trim();
			String ypmc=request.getParameter("ypmc");//药品编码
			String yplb=request.getParameter("yplb");//药品库房
			String ypjx=request.getParameter("ypjx");//药品剂型
			String ypdw=request.getParameter("ypdw");//药品单位
			String ypjj=request.getParameter("ypjj");//药品进价
			String ypsl=request.getParameter("ypsl");//药品数量
			double sumjinhuodouble = Double.parseDouble(ypjj) * Integer.parseInt(ypsl);
			String sumjinhuo = String.valueOf(sumjinhuodouble);
			String jhrq=request.getParameter("jhrq");//获得药品进货日期
			String ypph=null;//药品批号由进货时间自动生成
			ypph = DateUtil.getDateTime("yyyyMMddHHmmss");
			String ypcd=request.getParameter("ypcd");//药品产地
			String yxq=request.getParameter("yxq");  //有效期
			String dqrq=request.getParameter("dqrq");//获得药品到期日期
			String sql = "insert into t_stroage (ypmc,yplb,ypjx,ypdw,ypjj,ypsl,sumjinhuo,jhrq,ypph,ypcd,yxq,dqrq,ypsysl)  " +
					"values('"+ypmc+"','"+yplb+"','"+ypjx+"','"+ypdw+"','"+ypjj+"','"+ypsl+"'," +
					"'"+sumjinhuo+"','"+jhrq+"','"+ypph+"','"+ypcd+"','"+yxq+"','"+dqrq+"','"+ypsl+"') ";
			DbUtil.add_modify(sql);
			request.getRequestDispatcher("/manage/ypjinhuo_info_manage.jsp").forward(request, response);
		} else if ("deljinhuo".equals(method)) {
			String[] id = request.getParameterValues("selectFlag");
			DbUtil.del("t_stroage", id);
			request.getRequestDispatcher("/manage/ypjinhuo_info_manage.jsp").forward(request, response);
		} else if ("modifyjinhuo".equals(method)) {
			int id = Integer.parseInt(request.getParameter("id"));
			String yplb=request.getParameter("yplb");//药品库房
			String ypjj=request.getParameter("ypjj");//药品进价
			String ypsl=request.getParameter("ypsl");//药品数量
			double sumjinhuodouble = Double.parseDouble(ypjj) * Integer.parseInt(ypsl);
			String sumjinhuo = String.valueOf(sumjinhuodouble);
			String yxq=request.getParameter("yxq");  //有效期
			String sql = "update t_stroage set yplb = '" +yplb+"', ypjj='"+ypjj+"', ypsl='"+ypsl+"', yxq='"+yxq+"', sumjinhuo='"+sumjinhuo+"', ypsysl='"+ypsl+"' where id = " + id;
			DbUtil.add_modify(sql);
			request.getRequestDispatcher("/manage/ypjinhuo_info_manage.jsp").forward(request, response);
		} 
	}
}